package com.codrim.cs.data.server.dao.entity;

import com.codrim.cs.data.rpc.dto.param.StatisticDataDTO;
import com.codrim.cs.data.server.dao.param.StatCsUniqueKey;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author Liang.Zhuge
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class StatCsGeneralDO extends AbstractStatCsEntity<StatCsGeneralDO.StatCsGeneralUniqueKey> {
    private Integer id;
    private Integer sdate;
    private String symbol;
    private Integer advertiserId;
    private Integer affiliateId;
    private Integer offerId;
    private Integer anonymous;
    private Integer reportType;
    private String countryId;
    private String sorceId;
    private String sub1;
    private String sub2;
    private String sub3;
    private String sub4;
    private String sub5;

    private Float singleAccessPrice;
    private Float singlePutPrice;

    private String browser;
    private Long click;
    private Long uclick;
    private Long gc;
    private Long conversion;
    private Float aprice;
    private Float pprice;
    private Long caps;
    private Long sc;

    /**
     * 客户ID
     */
    private Integer customerId;
    /**
     * 自己公司为广告主设置的商务经理ID
     */
    private Integer advAdvertiserManagerId;
    /**
     * 自己公司为渠道设置的渠道经理ID
     */
    private Integer advAffiliateManagerId;
    /**
     * 渠道端设置的商务经理
     */
    private Integer affAdvertiserManagerId;

    private Integer advAdvertiserManagerDepartmentId;
    private Integer advAffiliateManagerDepartmentId;
    private Integer affAdvertiserManagerDepartmentId;

    private Integer accessType;

    public StatCsGeneralDO() {}

    public StatCsGeneralDO(int sdate, StatisticDataDTO statisticData) {
        setSdate(sdate);
        setSymbol(statisticData.getCurrencySymbol());
        setAdvertiserId(statisticData.getAdvId());
        setAffiliateId(statisticData.getAffId());
        setOfferId(statisticData.getOfferId());
        setAnonymous(statisticData.getAnonymous());
        setReportType(statisticData.getReportType());
        setSorceId(statisticData.getSourceId());
        setSub1(statisticData.getSub1());
        setSub2(statisticData.getSub2());
        setSub3(statisticData.getSub3());
        setSub4(statisticData.getSub4());
        setSub5(statisticData.getSub5());

        setSingleAccessPrice(statisticData.getSingleAccessPrice());
        setSinglePutPrice(statisticData.getSinglePutPrice());

        setClick((long) statisticData.getClick());
        setUclick((long) statisticData.getUclick());
        setGc((long) statisticData.getGc());
        setConversion((long) statisticData.getConversion());
        setAprice(statisticData.getAccessPrice());
        setPprice(statisticData.getPutPrice());
        setCaps((long) statisticData.getCaps());
        setSc((long) statisticData.getSc());

        setCustomerId(statisticData.getCustomerId());
        setAdvAdvertiserManagerId(statisticData.getAdvAdvertiserManagerId());
        setAdvAffiliateManagerId(statisticData.getAdvAffiliateManagerId());
        setAffAdvertiserManagerId(statisticData.getAffAdvertiserManagerId());
        setAdvAdvertiserManagerDepartmentId(statisticData.getAdvAdvertiserManagerDepartmentId());
        setAdvAffiliateManagerDepartmentId(statisticData.getAdvAffiliateManagerDepartmentId());
        setAffAdvertiserManagerDepartmentId(statisticData.getAffAdvertiserManagerDepartmentId());

        this.accessType = statisticData.getAccessType();
    }

    @Override
    public void plus(AbstractStatCsEntity source) {
        StatCsGeneralDO cSource = (StatCsGeneralDO) source;

        this.click = add(this.click, cSource.click);
        this.uclick = add(this.uclick, cSource.uclick);
        this.gc = add(this.gc, cSource.gc);
        this.conversion = add(this.conversion, cSource.conversion);
        this.aprice = add(this.aprice, cSource.aprice);
        this.pprice = add(this.pprice, cSource.pprice);
        this.caps = add(this.caps, cSource.caps);
        this.sc = add(this.sc, cSource.sc);
    }

    @Override
    public void plus(StatisticDataDTO cSource) {
        this.click = add(this.click, cSource.getClick());
        this.uclick = add(this.uclick, cSource.getUclick());
        this.gc = add(this.gc, cSource.getGc());
        this.conversion = add(this.conversion, cSource.getConversion());
        this.aprice = add(this.aprice, cSource.getAccessPrice());
        this.pprice = add(this.pprice, cSource.getPutPrice());
        this.caps = add(this.caps, cSource.getCaps());
        this.sc = add(this.sc, cSource.getSc());
    }

    @Override
    public StatCsGeneralUniqueKey createUniqueKey() {
        return new StatCsGeneralUniqueKey(sdate, symbol, advertiserId,
                affiliateId, offerId, reportType, anonymous, countryId, sorceId,
                sub1, sub2, sub3, sub4, sub5, customerId, advAdvertiserManagerId,
                advAffiliateManagerId, affAdvertiserManagerId,
                this.singleAccessPrice, this.singlePutPrice, this.accessType);
    }

    @EqualsAndHashCode(callSuper = true)
    @Data
    public static class StatCsGeneralUniqueKey extends StatCsUniqueKey {
        private String symbol;
        private Integer advertiserId;
        private Integer affiliateId;
        private Integer offerId;
        private Integer anonymous;
        private Integer reportType;
        private String countryId;
        private String sorceId;
        private String sub1;
        private String sub2;
        private String sub3;
        private String sub4;
        private String sub5;

        private Float singleAccessPrice;
        private Float singlePutPrice;

        /**
         * 客户ID
         */
        private Integer customerId;
        /**
         * 商务经理ID
         */
        private Integer advAdvertiserManagerId;
        /**
         * 渠道经理ID
         */
        private Integer advAffiliateManagerId;

        private Integer affAdvertiserManagerId;

        private Integer accessType;

        public StatCsGeneralUniqueKey(int sdate, String symbol, Integer advertiserId, Integer affiliateId,
                Integer offerId, Integer reportType, Integer anonymous, String countryId,
                String sorceId, String sub1, String sub2, String sub3, String sub4, String sub5,
                Integer customerId, Integer advAdvertiserManagerId, Integer advAffiliateManagerId,
                Integer affAdvertiserManagerId, float singleAccessPrice, float singlePutPrice,
                Integer accessType) {
            super(sdate);
            this.symbol = symbol;
            this.advertiserId = advertiserId;
            this.affiliateId = affiliateId;
            this.offerId = offerId;
            this.anonymous = anonymous;
            this.reportType = reportType;
            this.countryId = countryId;
            this.sorceId = sorceId;
            this.sub1 = sub1;
            this.sub2 = sub2;
            this.sub3 = sub3;
            this.sub4 = sub4;
            this.sub5 = sub5;

            this.singleAccessPrice = singleAccessPrice;
            this.singlePutPrice = singlePutPrice;

            this.customerId = customerId;
            this.advAdvertiserManagerId = advAdvertiserManagerId;
            this.advAffiliateManagerId = advAffiliateManagerId;
            this.affAdvertiserManagerId = affAdvertiserManagerId;
            this.accessType = accessType;
        }
    }
}
